//
//  SHArrayViewController.m
//  SDemo
//
//  Created by gg on 2018/7/30.
//  Copyright © 2018年 gg. All rights reserved.
//

#import "SHArrayViewController.h"

@interface SHArrayViewController ()

@property (nonatomic, strong) NSMutableArray *mutableArr;
@property (nonatomic, copy)NSArray *arr;

@end

@implementation SHArrayViewController


-(NSMutableArray *)mutableArr {
    if (_mutableArr == nil) {
        _mutableArr = @[@1,@3,@5].mutableCopy;
    }
    
    return _mutableArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"深拷贝和浅拷贝";
    self.view.backgroundColor = [UIColor whiteColor];

    
    [self mutable_Copy];
    
    UITextField *textfiled = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, 200, 45)];
    textfiled.placeholder = @"请输入";
    textfiled.font = [UIFont systemFontOfSize:15];
   
    [self.view addSubview:textfiled];
    

    
}

-(void) mutable_Copy {
    
//        NSMutableArray *newMuArr = self.mutableArr;
//        NSArray *newArr = @[@3,@4,@5];
//
//        [newMuArr removeAllObjects];
//        [newMuArr addObjectsFromArray:newArr];
//        NSLog(@"new: %@ , mutableArr : %@",newMuArr, self.mutableArr);
    
    //下面的原数组不变，上面的原数组会跟着变化
    NSMutableArray *newMuArr = self.mutableArr.mutableCopy;
    NSArray *newArr = @[@3,@4,@5];
    
    [newMuArr removeAllObjects];
    [newMuArr addObjectsFromArray:newArr];
    NSLog(@"new: %@ , mutableArr : %@",newMuArr, self.mutableArr);
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
